#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int t,n,m,l,v,a[N],b[N],c[N],d[N],sum;
bool e[N];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    for(int j=1;j<=t;++j){
        cin>>n>>m>>l>>v;
        for(int i=1;i<=n;++i)
            cin>>b[i]>>c[i]>>a[i];
        for(int i=1;i<=m;++i)
            cin>>d[i];
        for(int i=1;i<=n;++i)
            if(c[i]>v) {
                sum++;
                e[i]=1;
            }
        sort(d+1,d+m+1);
        for(int i=1;i<=n;++i){
            if(b[i]>d[m] && e[i]==1) sum--;
        }
        if(sum==0) cout<<sum<<" "<<m<<"\n";
        else cout<<sum<<" "<<m-1<<"\n";
        sum=0;
        for(int i=1;i<=n;++i) e[i]=0;
    }

}
